//
//  MyCarsViewController.m
//  PeopleStreet
//
//  Created by 刘建峰 on 16/7/8.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "MyCarsViewController.h"
#import "MyCarsTableViewCell.h"

static NSString * cellIndentfier = @"MyCarsTableViewCell";


@interface MyCarsViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,assign)NSInteger selectedIndex;

@end

@implementation MyCarsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    
    [self.tableView registerNib:[UINib nibWithNibName:cellIndentfier bundle:nil] forCellReuseIdentifier:cellIndentfier];
    
    _tableView.dataSource = self;
    _tableView.delegate = self;

}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark  ==== 编辑
- (IBAction)editHandel:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"EditMyCar"];
    [self.navigationController   pushViewController:page animated:YES];
}


#pragma mark == 添加车辆

- (void)addCar{
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"AddCar"];
    [self.navigationController   pushViewController:page animated:YES];
}

#pragma mark -- UITableViewDataSource


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 48*VerticalRatio();
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 48), NO)];
    view.backgroundColor = [UIColor whiteColor];
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = flexibleFrame(CGRectMake(0, 0, 320, 48), NO);
    [button setTitle:@"  请点击添加车辆" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithWhite:0.584 alpha:1.000] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"myCars1"] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15*VerticalTexeRatio()];
    [button addTarget:self action:@selector(addCar) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    return view;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        return 47*VerticalRatio();
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        MyCarsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfier];
        if (cell == nil) {
            cell= [[MyCarsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfier];
        }
        
    
    cell.carNumber.selected = NO;
    cell.setButton.selected = NO;
    cell.setButton.layer.borderColor = [UIColor colorWithWhite:0.878 alpha:1.000].CGColor;
    if (indexPath.row == _selectedIndex) {
        cell.carNumber.selected = YES;
        cell.setButton.selected = YES;
        cell.setButton.layer.borderColor = [UIColor colorWithRed:1.000 green:0.647 blue:0.035 alpha:1.000].CGColor;
    }
    cell.setBlock = ^(){
        _selectedIndex = indexPath.row;
        [_tableView reloadData];
    };
        //        NSDictionary * dic = _listArray[indexPath.row];
        //
        //        cell.superTitle.text  = [NSString stringWithFormat:@"%@",dic[@"mmdeName"]];
        //        cell.superDetail.text  = [NSString stringWithFormat:@"%@",dic[@"mmdeContent"]];
        //        cell.time.text = [ NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"]];
        //        if ([NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"] ].length>0) {
        //            cell.time.text = [Common updateTimeForData:[NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"] ]];
        //        }
        //
        return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
